import Vue from 'vue';
import App from './App.vue';
import router from './router';
import 'normalize.css';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);
Vue.config.productionTip = false;

let instance = null;

function render(props = {}) {
    instance = new Vue({
        router,
        render: (h) => h(App),
    }).$mount(props.container ? props.container.querySelector('#app') : '#app');
}

if (window.__POWERED_BY_QIANKUN__) {
    // eslint-disable-next-line no-undef
    __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
}

if (!window.__POWERED_BY_QIANKUN__) {
    render();
}

// 生命周期
export async function bootstrap (props) {
    console.log('project bootstrap', props);
}

export async function mount (props) {
    render(props);
}

export async function unmount () {
    // 销毁
    instance.$destroy();
    instance = null;
}
